export default function saveImageToPhotosAlbum(data, title, name) {
  title = title || '保存成功，请进入相册查看'
  data = data.replace(/^data:image\/\w+;base64,/, '') //去掉data:image/png;base64,
  let filePath = wx.env.USER_DATA_PATH + '/' +(name || +new Date()) + '.png'
  console.log(data)
  // uni.saveImageToPhotosAlbum({
  //   filePath,
  //   success: ()=>{
  //     uni.showToast({
  //       title,
  //       icon: 'none',
  //       duration: 5000,
  //     })
  //   }
  // })
  uni.getFileSystemManager().writeFile({
    filePath, //创建一个临时文件名
    data, //写入的文本或二进制数据
    encoding: 'base64', //写入当前文件的字符编码
    success: (res) => {
      console.log('保存到相册成功',res)
      uni.saveImageToPhotosAlbum({
        filePath: filePath,
        success: function () {
          uni.showToast({
            title,
            icon: 'none',
            duration: 5000,
          })
        },
        fail: function (err) {
          // console.log(err.errMsg);
        },
      })
    },
    fail: (err) => {
      //console.log(err)
    },
  })
}
